package org.leumasjaffe.initiativeTracker.distributed.controller;

import static org.leumasjaffe.initiativeTracker.operator.InitiativeController.tracker;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.leumasjaffe.initiativeTracker.entity.PC;
import org.w3c.dom.NamedNodeMap;

import edu.wpi.heineman.xml.Message;
import edu.wpi.heineman.client.IMessageHandler;

@NonNullByDefault
public class SurgeHandler implements IMessageHandler {

	@Override
	public void process(Message response) {
		NamedNodeMap map = response.contents.getFirstChild().getFirstChild().getAttributes();

		int id = Integer.decode(map.getNamedItem("id").getNodeValue());
		int bonus = Integer.decode(map.getNamedItem("value").getNodeValue());
		@SuppressWarnings("null")
		PC pc = (PC) tracker(response.contents.getFirstChild()
				.getAttributes().getNamedItem("game").getNodeValue()).list.lookup(id).getCharacter();
		
		pc.surge(bonus);
	}

	@Override
	public IMessageHandler newCopy() {
		return new SurgeHandler();
	}

}
